package com.xsz.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Set;
import javax.persistence.*;

/**
 * 用户表
 */
@Entity
@Table(name="tb_user")
@Getter
@Setter
public class User implements Serializable{
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /**主键ID**/
    @Id
    @Column(length=60)
    private String id;

    @Column(length=30)
    /**用户名**/
    private String name;

    @Column(length=90)
    /**用户登录密码**/
    private String pwd;

    /**头像**/
    private String logo;

    @Column(length=30)
    /**用户手机号码**/
    private String mobile;


    /**用户性别**/
    private String sex;

    /**加密密码的盐**/
    private String salt;

    /**密码盐**/
    public String getCredentialsSalt(){
        return this.name+this.salt;

    }

    @ManyToMany(fetch=FetchType.EAGER)//立即从数据库中进行加载数据;
    @JoinTable(name = "TbUserRole", joinColumns = { @JoinColumn(name = "uid") }, inverseJoinColumns
            ={@JoinColumn(name = "roleId") })
    private Set<Role> roles;// 一个用户具有多个角色

    // 用户 - 会议关系定义;
    @JsonIgnore
    @ManyToMany
    @JoinTable(name="TbMeetUser",joinColumns={@JoinColumn(name="uid")},inverseJoinColumns={@JoinColumn(name="mid")})
    private Set<User> meetings;// 一个用户可以参加多个会议
}
